#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QDebug>
#include <QPushButton>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{
    // 创建 QMessageBox
    QMessageBox* messageBox = new QMessageBox(this);
    messageBox->setAttribute(Qt::WA_DeleteOnClose);
    messageBox->setWindowTitle("对话框窗口标题");
    messageBox->setText("这是对话框的文本");
    messageBox->setIcon(QMessageBox::Information);
    messageBox->setStandardButtons(QMessageBox::Ok | QMessageBox::Save | QMessageBox::Cancel);

//    QPushButton* button = new QPushButton("按钮", messageBox);
//    messageBox->addButton(button, QMessageBox::AcceptRole);

    // 当用户点击按钮使对话框关闭之后，通过这里的返回值就可以知道用户点击的按钮
    int result = messageBox->exec();
    if(result == QMessageBox::Ok) {
        qDebug() << "OK";
    } else if(result = QMessageBox::Save) {
        qDebug() << "Save";
    } else if(result == QMessageBox::Cancel) {
        qDebug() << "Cancel";
    }
}
